﻿using System;
using Jayden.Dll.Core.Membership;
using Jayden.Dll.Core.Persistence;
using Jayden.Dll.Core.Persistence.Attributes;

namespace Jayden.Dll.Entities.Common
{
	[Table]
	public class Contact : ObjectBase, IComparable<Contact>
	{

		private string m_UserTitle;
		private string m_CultureCode;
		private string m_Email;
		private string m_FirstName;
		private string m_LastName;
		private string m_UserName;
		private DateTime m_CreationDate;
		private string m_Category;
		private string m_Title;
		private string m_Body;

		public Contact(UnitOfWork uow) : base(uow, 0) { }

		[Field(PrimaryKey=true, AutoIncrement=true)]
		public long ContactId { get { return (long)ObjectId[0]; } set { ObjectId[0] = value; } }
		[Field]
		public string UserTitle { get { return m_UserTitle; } set { m_UserTitle = value; } }
		[Field(Nullable = true)]
		public string CultureCode { get { return m_CultureCode; } set { m_CultureCode = value; } }
		[Field]
		public string Email { get { return m_Email; } set { m_Email = value; } }
		[Field(Nullable = true)]
		public string FirstName { get { return m_FirstName; } set { m_FirstName = value; } }
		[Field(Nullable = true)]
		public string LastName { get { return m_LastName; } set { m_LastName = value; } }
		[Field(Nullable = true)]
		public string UserName { get { return m_UserName; } set { m_UserName = value; } }
		[Field]
		public DateTime CreationDate { get { return m_CreationDate; } set { m_CreationDate = value; } }
		[Field(Nullable = true)]
		public string Category { get { return m_Category; } set { m_Category = value; } }
		[Field]
		public string Title { get { return m_Title; } set { m_Title = value; } }
		[Field]
		public string Body { get { return m_Body; } set { m_Body = value; } }

		private User m_User;
		public User User
		{
			get
			{
				if (m_User == null && !string.IsNullOrWhiteSpace(UserName))
					m_User = System.Web.Security.Membership.GetUser(UserName) as User;
				return m_User;
			}
		}

		public int CompareTo(Contact other) { return -m_CreationDate.CompareTo(other.m_CreationDate); }
	}
}
